From: Dan Winship Date: Mon, 9 Aug 2010 17:18:15 +0000 (-0400) Subject: [MessageTray] remove Source IDs X-Git-Tag: archive/raspbian/50.5-1+rpi1~1^2~1013^2^2~9805 X-Git-Url: https://dgit.raspbian.org/%22http://www.example.com/cgi/%22/%22http:/www.example.com/cgi/%22?a=commitdiff_plain;h=d3031b406ab0c6bc2bacadc65e0ad9f0a99f9df3;p=gnome-shell.git [MessageTray] remove Source IDs The tray itself does not actually need them, and to make status icon sources work correctly the NotificationDaemon will need to be tracking its sources by two separate IDs, so the existing system won't work. Also remove MessageTray.removeSourceByApp(), which is NotificationDaemon-specific, and implement the functionality in notificationDaemon.js instead. https://bugzilla.gnome.org/show_bug.cgi?id=627303 --- diff --git a/js/ui/messageTray.js b/js/ui/messageTray.js index f3ea1b5a0..6bbd6448f 100644 --- a/js/ui/messageTray.js +++ b/js/ui/messageTray.js @@ -550,13 +550,12 @@ Notification.prototype = { }; Signals.addSignalMethods(Notification.prototype); -function Source(id, title, createIcon) { - this._init(id, title, createIcon); +function Source(title, createIcon) { + this._init(title, createIcon); } Source.prototype = { - _init: function(id, title, createIcon) { - this.id = id; + _init: function(title, createIcon) { this.title = title; if (createIcon) this.createIcon = createIcon; @@ -809,7 +808,7 @@ MessageTray.prototype = { this._updateState(); })); - this._summaryItems = {}; + this._summaryItems = []; this._longestSummaryItem = null; }, @@ -827,12 +826,20 @@ MessageTray.prototype = { }, contains: function(source) { - return this._summaryItems.hasOwnProperty(source.id); + return this._getIndexOfSummaryItemForSource(source) >= 0; + }, + + _getIndexOfSummaryItemForSource: function(source) { + for (let i = 0; i < this._summaryItems.length; i++) { + if (this._summaryItems[i].source == source) + return i; + } + return -1; }, add: function(source) { if (this.contains(source)) { - log('Trying to re-add source ' + source.id); + log('Trying to re-add source ' + source.title); return; } @@ -844,14 +851,14 @@ MessageTray.prototype = { let newItemTitleWidth = summaryItem.getTitleNaturalWidth(); if (newItemTitleWidth > minTitleWidth) { - for (sourceId in this._summaryItems) { - this._summaryItems[sourceId].setMinTitleWidth(newItemTitleWidth); + for (let i = 0; i < this._summaryItems.length; i++) { + this._summaryItems[i].setMinTitleWidth(newItemTitleWidth); } summaryItem.setMinTitleWidth(newItemTitleWidth); this._longestSummaryItem = summaryItem; } - this._summaryItems[source.id] = summaryItem; + this._summaryItems.push(summaryItem); source.connect('notify', Lang.bind(this, this._onNotify)); @@ -872,7 +879,8 @@ MessageTray.prototype = { }, removeSource: function(source) { - if (!this.contains(source)) + let index = this._getIndexOfSummaryItemForSource(source); + if (index == -1) return; // remove all notifications with this source from the queue @@ -883,26 +891,26 @@ MessageTray.prototype = { } this._notificationQueue = newNotificationQueue; - this._summary.remove_actor(this._summaryItems[source.id].actor); + this._summary.remove_actor(this._summaryItems[index].actor); if (this._summary.get_children().length > 0) this._summaryNeedsToBeShown = true; else this._summaryNeedsToBeShown = false; - delete this._summaryItems[source.id]; + this._summaryItems.splice(index, 1); if (this._longestSummaryItem.source == source) { let maxTitleWidth = 0; this._longestSummaryItem = null; - for (sourceId in this._summaryItems) { - let summaryItem = this._summaryItems[sourceId]; + for (let i = 0; i < this._summaryItems.length; i++) { + let summaryItem = this._summaryItems[i]; if (summaryItem.getTitleNaturalWidth() > maxTitleWidth) { maxTitleWidth = summaryItem.getTitleNaturalWidth(); this._longestSummaryItem = summaryItem; } } - for (sourceId in this._summaryItems) { - this._summaryItems[sourceId].setMinTitleWidth(maxTitleWidth); + for (let i = 0; i < this._summaryItems.length; i++) { + this._summaryItems[i].setMinTitleWidth(maxTitleWidth); } } @@ -925,12 +933,6 @@ MessageTray.prototype = { this._updateState(); }, - removeSourceByApp: function(app) { - for (let sourceId in this._summaryItems) - if (this._summaryItems[sourceId].source.app == app) - this.removeSource(this._summaryItems[sourceId].source); - }, - removeNotification: function(notification) { if (this._notification == notification && (this._notificationState == State.SHOWN || this._notificationState == State.SHOWING)) { if (this._notificationTimeoutId) { @@ -947,12 +949,6 @@ MessageTray.prototype = { this._notificationQueue.splice(index, 1); }, - getSource: function(id) { - if (this._summaryItems[id]) - return this._summaryItems[id].source; - return null; - }, - _getNotification: function(id, source) { if (this._notification && this._notification.id == id) return this._notification; diff --git a/js/ui/notificationDaemon.js b/js/ui/notificationDaemon.js index a6a55c5bf..4e7802281 100644 --- a/js/ui/notificationDaemon.js +++ b/js/ui/notificationDaemon.js @@ -107,6 +107,7 @@ NotificationDaemon.prototype = { Lang.bind(this, this._acquiredName), Lang.bind(this, this._lostName)); + this._sources = {}; this._currentNotifications = {}; Shell.WindowTracker.get_default().connect('notify::focus-app', @@ -140,13 +141,9 @@ NotificationDaemon.prototype = { } }, - _sourceId: function(id) { - return 'source-' + id; - }, - Notify: function(appName, replacesId, icon, summary, body, actions, hints, timeout) { - let source = Main.messageTray.getSource(this._sourceId(appName)); + let source = this._sources[appName]; let id = null; // Filter out notifications from Empathy, since we @@ -167,13 +164,18 @@ NotificationDaemon.prototype = { // been acknowledged. if (source == null) { let title = appNameMap[appName] || appName; - source = new Source(this._sourceId(appName), title, icon, hints); + source = new Source(title, icon, hints); Main.messageTray.add(source); + this._sources[appName] = source; source.connect('clicked', Lang.bind(this, function() { source.destroy(); })); + source.connect('destroy', Lang.bind(this, + function() { + delete this._sources[appName]; + })); let sender = DBus.getCurrentMessageContext().sender; let busProxy = new Bus(); @@ -265,8 +267,16 @@ NotificationDaemon.prototype = { _onFocusAppChanged: function() { let tracker = Shell.WindowTracker.get_default(); - if (tracker.focus_app) - Main.messageTray.removeSourceByApp(tracker.focus_app); + if (!tracker.focus_app) + return; + + for (let id in this._sources) { + let source = this._sources[id]; + if (source.app == tracker.focus_app) { + source.destroy(); + return; + } + } }, _actionInvoked: function(notification, action, source, id) { @@ -291,15 +301,15 @@ NotificationDaemon.prototype = { DBus.conformExport(NotificationDaemon.prototype, NotificationDaemonIface); -function Source(sourceId, title, icon, hints) { - this._init(sourceId, title, icon, hints); +function Source(title, icon, hints) { + this._init(title, icon, hints); } Source.prototype = { __proto__: MessageTray.Source.prototype, - _init: function(sourceId, title, icon, hints) { - MessageTray.Source.prototype._init.call(this, sourceId, title); + _init: function(title, icon, hints) { + MessageTray.Source.prototype._init.call(this, title); this.app = null; this._openAppRequested = false; diff --git a/js/ui/telepathyClient.js b/js/ui/telepathyClient.js index e23f4fa1a..722dffc48 100644 --- a/js/ui/telepathyClient.js +++ b/js/ui/telepathyClient.js @@ -445,7 +445,7 @@ Source.prototype = { __proto__: MessageTray.Source.prototype, _init: function(accountPath, connPath, channelPath, targetHandle, targetHandleType, targetId) { - MessageTray.Source.prototype._init.call(this, targetId, targetId); + MessageTray.Source.prototype._init.call(this, targetId); this._accountPath = accountPath; diff --git a/js/ui/windowAttentionHandler.js b/js/ui/windowAttentionHandler.js index ceba3f9ef..fa8aefaad 100644 --- a/js/ui/windowAttentionHandler.js +++ b/js/ui/windowAttentionHandler.js @@ -14,10 +14,12 @@ function WindowAttentionHandler() { WindowAttentionHandler.prototype = { _init : function() { + this._startupIds = {}; + this._sources = {}; + let display = global.screen.get_display(); display.connect('window-demands-attention', Lang.bind(this, this._onWindowDemandsAttention)); let tracker = Shell.WindowTracker.get_default(); - this._startupIds = {}; tracker.connect('startup-sequence-changed', Lang.bind(this, this._onStartupSequenceChanged)); }, @@ -29,10 +31,6 @@ WindowAttentionHandler.prototype = { } }, - _sourceId : function(appId) { - return 'attention-' + appId; - }, - _getTitle : function(app, window) { if (this._startupIds[window.get_startup_id()]) return app.get_name(); @@ -61,12 +59,15 @@ WindowAttentionHandler.prototype = { let tracker = Shell.WindowTracker.get_default(); let app = tracker.get_window_app(window); + let appId = app.get_id(); - let source = Main.messageTray.getSource(this._sourceId(app.get_id())); + let source = this._sources[appId]; if (source == null) { - source = new Source(this._sourceId(app.get_id()), app, window); + source = new Source(app, window); + this._sources[appId] = source; Main.messageTray.add(source); source.connect('clicked', Lang.bind(this, function() { source.destroy(); })); + source.connect('destroy', Lang.bind(this, function() { delete this._sources[appId]; })); } let notification = new MessageTray.Notification(window.get_startup_id(), source, this._getTitle(app, window), this._getBanner(app, window), true); @@ -82,15 +83,15 @@ WindowAttentionHandler.prototype = { } }; -function Source(sourceId, app, window) { - this._init(sourceId, app, window); +function Source(app, window) { + this._init(app, window); } Source.prototype = { __proto__ : MessageTray.Source.prototype, - _init: function(sourceId, app, window) { - MessageTray.Source.prototype._init.call(this, sourceId, app.get_name()); + _init: function(app, window) { + MessageTray.Source.prototype._init.call(this, app.get_name()); this._window = window; this._app = app; },